package com.android.qjpmc.application_module.home.viewModel;

import com.android.qjpmc.application_module.home.contract.AlarmRecordContract;
import com.android.qjpmc.application_module.home.contract.CallPoliceContract;
import com.android.qjpmc.application_module.home.model.AlarmRecordModel;
import com.android.qjpmc.application_module.home.model.StationDataModel;
import com.android.qjpmc.bean.AlarmRecordItemBean;
import com.android.qjpmc.bean.PwrDeviceBean;
import com.android.qjpmc.bean.SiteStationBean;
import com.android.qjpmc.bean.StationDataBean;
import com.android.qjpmc.data_module.PwrDataModule;
import com.android.qjpmc.widget.mvvm.factory.CreateModel;
import com.android.qjpmc.widget.retrofithelper.rxsubscriber.ProgressObserver;

import java.util.List;
import java.util.Map;

@CreateModel(StationDataModel.class)
public class AlarmRecordsViewModel extends AlarmRecordContract.ViewModel {
    public void getStationList() {

        mModel.getStationList().subscribe(new ProgressObserver<List<SiteStationBean>>(false, this) {
                                              @Override
                                              public void _onNext(List<SiteStationBean> siteStationBeans) {
                                                  //更新到界面...
                                                  PwrDataModule.getInstance().CreateStationByBeanList(siteStationBeans);
                                                  PwrDataModule.getInstance().SetStationDownMark(1);
                                                  mView.returnSiteStationData(siteStationBeans);
                                              }

                                              @Override
                                              public void _onError(String errorMessage, int errorCode) {
                                                  super._onError(errorMessage, errorCode);
                                              }
                                          }
        );
    }

    public void getGroupListOfStation(String stationId) {

        mModel.getGroupListOfStation(stationId).subscribe(new ProgressObserver<List<PwrDeviceBean>>(true, this) {
            @Override
            public void _onNext(List<PwrDeviceBean> pwrDeviceBeans) {
                int nStationID = 0;
                nStationID = Integer.parseInt(stationId);
                //todo 胖胖修改: 数据不统一 注释掉了
                // PwrDataModule.getInstance().CreateAllPowerDeviceOfAStation(nStationID, pwrDeviceBeans);
                if (pwrDeviceBeans != null)
                    for (PwrDeviceBean pwrDeviceBean : pwrDeviceBeans) {
                        pwrDeviceBean.stationId = stationId;
                    }

                mView.returnCompanyDevicesListData(pwrDeviceBeans);
            }
        });
    }

    public void getAlarmRecordList(Map<String, Object> queryParams) {
        mModel.getAlarmRecordList(queryParams).subscribe(new ProgressObserver<List<AlarmRecordItemBean>>(true, this) {
            @Override
            public void _onNext(List<AlarmRecordItemBean> alarmRecords) {

                mView.returnAlarmRecordList(alarmRecords);
            }
        });

    }
}
